package home.projects.recipes.chapfour;

import org.springframework.beans.factory.config.AbstractFactoryBean;

public class ProductDiscountFactory extends AbstractFactoryBean {

   private Product product;

   private double discount;

   public void setProduct(Product product) {
      this.product = product;
   }

   public void setDiscount(double discount) {
      this.discount = discount;
   }

   /*
    * (non-Javadoc)
    * 
    * @see
    * org.springframework.beans.factory.config.AbstractFactoryBean#createInstance
    * ()
    */
   @Override
   protected Object createInstance() throws Exception {
      double discountedPrice = product.getPrice() * discount;
      return new Product(product.getProductId(), product.getPrice()
            - discountedPrice);
   }

   /*
    * (non-Javadoc)
    * 
    * @see
    * org.springframework.beans.factory.config.AbstractFactoryBean#getObjectType
    * ()
    */
   @Override
   public Class<Product> getObjectType() {
      return Product.class;
   }

}
